﻿using System;
using System.Net;
using System.Web;
using System.Configuration;

using SBPweb.Forge.Contracts.Logging;

namespace SBPweb.Communication.Server.Presentation.Web
{

    public class Global : System.Web.HttpApplication
    {

        #region Property accessors

        internal static readonly ILogManager LogManager = new SBPweb.Forge.Logger.LogManager();
        //internal static Library.Sockets.SocketHost SocketHost = new Library.Sockets.SocketHost();

        #endregion

        #region Application life-cycle

        protected void Application_Start(object sender, EventArgs e)
        {
            //LogManager.Initialize();
            //LogManager.WriteInfo(sender, "Application started.", "General");
            
            //SocketHost.LogManager = LogManager;

            //string hostPublicIp = ConfigurationSettings.AppSettings["socketHostPublicIp"];
            //if (string.IsNullOrEmpty(hostPublicIp))
            //{
            //    IPHostEntry hE = Dns.Resolve(Dns.GetHostName());
            //    hostPublicIp = hE.AddressList[hE.AddressList.Length - 1].ToString();
            //}
            //SocketHost.StartListening(IPAddress.Parse(hostPublicIp));
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            LogManager.WriteCritical(sender, Server.GetLastError(), "Exception");
        }

        protected void Application_End(object sender, EventArgs e)
        {
            LogManager.WriteInfo(sender, "Application ended.", "General");
            LogManager.Terminate();
        }

        #endregion

        #region Session life-cycle

        protected void Session_Start(object sender, EventArgs e)
        {
            LogManager.WriteVerbose(sender, "Session started.", "General");
        }

        protected void Session_End(object sender, EventArgs e)
        {
            LogManager.WriteVerbose(sender, "Session end.", "General");
        }

        #endregion

        #region Request life-cycle

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        #endregion

    }

}